package com.feishi.core.analytic.element;

import com.feishi.core.analytic.PoType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by caixq on 5/12 012.
 */
public  class AnalyticContentElement extends AnalyticElement {

    protected Map<String,AnalyticStaticContentTypeDataElement> contentTypeMap=new HashMap<>();
    protected List<AnalyticStaticContentTypeDataElement> contentTypeList=new ArrayList<>();
    protected AnalyticStaticInputDataElement contentLength;
    protected AnalyticStaticContentEncodeDataElement contentEncode;
    private boolean repeatable=false;

    public AnalyticContentElement() {
        init(String.valueOf(PoType.ELEMENT_CONTENT),PoType.ELEMENT_CONTENT);
    }
    public AnalyticContentElement(String name) {
        init(name,PoType.ELEMENT_CONTENT);
    }
    private void init(String name, int type) {
        this.type=type;
        this.name=name;
    }


    public AnalyticStaticContentTypeDataElement getContentType(String typeName) {
        return contentTypeMap.get(typeName);
    }

    public void setContentType(AnalyticStaticContentTypeDataElement contentType) {
        this.contentTypeMap.put(contentType.getName(),contentType);
        contentTypeList.add(contentType);
    }

    public AnalyticStaticInputDataElement getContentLength() {
        return contentLength;
    }

    public void setContentLength(AnalyticStaticInputDataElement contentLength) {
        this.contentLength = contentLength;
    }

    public AnalyticStaticContentEncodeDataElement getContentEncode() {
        return contentEncode;
    }

    public void setContentEncode(AnalyticStaticContentEncodeDataElement contentEncode) {
        this.contentEncode = contentEncode;
    }
    public boolean isRepeatable(){
        for(AnalyticStaticContentTypeDataElement contentType:contentTypeList){
            if(contentType.isRepeatable()){
                return true;
            }
        }
        return this.repeatable;
    }
}
